import { action, computed, makeObservable, observable } from 'mobx';
import { FetchMeta } from 'store/RootStore/ApiStore';

type PrivateFields = '_loading';

export default class PageLoaderStore {
    private _loading = false;

    constructor() {
        makeObservable<PageLoaderStore, PrivateFields>(this, {
            _loading: observable.ref,
            getFetchRequestsMeta: action.bound,
            loading: computed,
        });
    }

    get loading(): boolean {
        return this._loading;
    }

    getFetchRequestsMeta(fetchMeta: FetchMeta[]): void {
        this._loading = fetchMeta.some((meta) => meta === FetchMeta.FETCHING);
    }
}
